/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.raip.io
 *
 * 版权所有，侵权必究！
 */

package com.cz.modules.job.task;

import cn.hutool.core.date.DateUtil;
import com.cz.common.utils.HCKNetSDKUtil;
import com.cz.common.utils.HikvisionApiUtil;
import com.cz.common.utils.ParkingUtil;
import nova.traffic.NovaTraffic;
import com.cz.modules.rll.entity.RllHourCountEntity;
import nova.traffic.been.DeviceMemorySize;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletOutputStream;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 测试定时任务(演示Demo，可删除)
 *
 * testTask为spring bean的名称
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component("testTask")
public class TestTask implements ITask {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void run(String params)  {
		logger.debug("TestTask定时任务正在执行，参数为：{}", params);
		if("1".equals(params)){
			NovaTraffic novaTraffic = new NovaTraffic("192.168.1.52", 5000);//北区
			//int ret = novaTraffic.getDeviceScreenshot("d:\\2.jpg");
			int  ret = novaTraffic.sendFile(new File("d:\\parkingN.png"),"parking.png");
			System.out.println("--------------传·N1完成");
			//bigtestN();
			NovaTraffic novaTraffic1 = new NovaTraffic("192.168.1.51", 5000);//南区
			int  ret4 = novaTraffic1.sendFile(new File("d:\\parkingS.png"),"parking.png");
			System.out.println("-----------------传·S2完成");
			//int ret = novaTraffic1.getDeviceScreenshot("d:\\3.jpg");
			//bigtestS();
		}
		if("2".equals(params)){
			bigtestN();
			bigtestS();
		}
		if("3".equals(params)){
			NovaTraffic novaTraffic = new NovaTraffic("192.168.1.52", 5000);//北区
			int ret = novaTraffic.getDeviceScreenshot("d:\\2.jpg");
			NovaTraffic novaTraffic1 = new NovaTraffic("192.168.1.51", 5000);//南区
			int ret1 = novaTraffic1.getDeviceScreenshot("d:\\3.jpg");
		}

	}

	public static void main(String[] args) throws IOException {
		//xiapingtest();
		/*ServerSocket serverSocket = new ServerSocket(5000);
		while (true) {
			Socket socket = serverSocket.accept();
			Thread t1 = new Thread(new Runnable() {
				public void run() {
					NovaTraffic novaTraffic = new NovaTraffic(socket);
					try {
							String name = novaTraffic.getDeviceName();
							System.out.println(name+"==========");
					} catch (Exception e) {
						e.printStackTrace();
					} finally {
						try {
							socket.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			});
			t1.start();
		}*/
		//NovaTraffic novaTraffic = new NovaTraffic("192.168.1.52", 5000);//北区
		//int ret = novaTraffic.getDeviceScreenshot("d:\\2.jpg");
		//int  ret = novaTraffic.sendFile(new File("d:\\parkingN.png"),"parkingN.png");
		//System.out.println("--------------传·N1完成");
		//bigtestN();
		NovaTraffic novaTraffic1 = new NovaTraffic("192.168.1.51", 5000);//南区
		//int  ret4 = novaTraffic1.sendFile(new File("d:\\parkingS.png"),"parkingS.png");
		//System.out.println("-----------------传·S2完成");
		int ret = novaTraffic1.getDeviceScreenshot("d:\\3.jpg");
		//bigtestS();
	}
	public static void xiapingtest() throws IOException {
		Socket soc = new Socket("192.168.0.4", 50100);
		OutputStreamWriter os= new OutputStreamWriter(soc.getOutputStream(), StandardCharsets.UTF_8);
		PrintWriter pw=new PrintWriter(os);
		try {
			//String aa="<?xml version=\"1.0\" encoding=\"UTF-8\"?><QDELITS type=\"ITS\"><ITS id=\"192.168.2.51\" Port=\"9999\"><PROG id=\"-1\"><ITEMS trad=\"0,15\" wh=\"160,128\"><ITEM type=\"2\" interval=\"65534\"><text color=\"3\" size=\"32\" style=\"0\"  font=\"宋体\">车位剩余 大车位:001小车位:001</text>" +
					//"</ITEM></ITEMS></PROG></ITS></QDELITS>";
			String aa="<?xml version=\"1.0\" encoding=\"UTF-8\"?><QDELITS type=\"ITS\"><ITS id=\"192.168.2.50\" Port=\"9999\"><PROG id=\"-1\"><ITEMS trad=\"0,15\" wh=\"160,128\"><ITEM type=\"2\" interval=\"65534\"><text color=\"2\" size=\"32\" style=\"0\"  font=\"宋体\">谨慎驾驶 安全出行</text>" +
					"</ITEM></ITEMS></PROG></ITS></QDELITS>";
			pw.write(aa);
			pw.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
		pw.close();
		os.close();
		soc.close();
	}
	public static void bigtestN(){
		NovaTraffic novaTraffic = new NovaTraffic("192.168.1.52", 5000);//北区
		String content = "[all]\r\n" +
				"items=1\r\n" +
				"[item1]\r\n" +
				"param=4294960,1,1,1,0,5,1,0,1\r\n" +
				"img1=0,0,parking.png,0,0,0\r\n" +
				"imgparam1=4294960\r\n" +
				"time1=820,0,200,84,4294960,1,123a91,2424,2,0,1,0,1,1,1,1,1,1,0,0,1,Asia/Shanghai,GMT+08:00,星期日|星期一|星期二|星期三|星期四|星期五|星期六\r\n" +
				//"clock1=860,10,148,148,8,4294960,Asia/Shanghai,GMT+08:00,0,5,2,1,5,3,4,2,1,1\r\n" +
				//"txtext1=0,100,0,288,3,3232,0,0,0,1,0,1,00000000,12,0,100,1,屏幕测试，敬请谅解,0,0,0,5,5,5\r\n"+
				"txt1=846,200,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam1=10,0\r\n" +
				"txt3=846,325,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam3=10,0\r\n" +
				"txt4=846,400,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam4=10,0\r\n" +
				"txt5=846,470,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam5=10,0\r\n" +
				"txt6=846,540,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam6=10,0\r\n" +
				"txtext1=820,85,200,24,2,2424,0,0,0,1,3,1,123a91,8,2,4294960,255,晴 10℃-27℃,0,0,0,5,5,5";
                    /*"txt6=820,85,2,2424,1,123a91,0,晴转多云10-27℃,200,24,0\r\n" +
                    "txtparam6=2,0";*/
		int ret = novaTraffic.sendPlayList(1, content);
		System.out.println(ret);
	}
	public static void bigtestS(){
		NovaTraffic novaTraffic = new NovaTraffic("192.168.1.51", 5000);//南区
		String content = "[all]\r\n" +
				"items=1\r\n" +
				"[item1]\r\n" +
				"param=4294960,1,1,1,0,5,1,0,1\r\n" +
				"img1=0,0,parking.png,0,0,0\r\n" +
				"imgparam1=4294960\r\n" +
				"time1=820,0,200,84,4294960,1,123a91,2424,2,0,1,0,1,1,1,1,1,1,0,0,1,Asia/Shanghai,GMT+08:00,星期日|星期一|星期二|星期三|星期四|星期五|星期六\r\n" +
				//"clock1=860,10,148,148,8,4294960,Asia/Shanghai,GMT+08:00,0,5,2,1,5,3,4,2,1,1\r\n" +
				//"txtext1=0,100,0,288,3,3232,0,0,0,1,0,1,00000000,12,0,100,1,屏幕测试，敬请谅解,0,0,0,5,5,5\r\n"+
				"txt1=846,220,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam1=10,0\r\n" +
				"txt3=846,352,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam3=10,0\r\n" +
				"txt4=846,430,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam4=10,0\r\n" +
				"txt5=846,525,2,2828,2,123a91,0,010,93,28,0\r\n" +
				"txtparam5=10,0\r\n" +
				"txtext1=820,85,200,24,2,2424,0,0,0,1,3,1,123a91,8,2,4294960,255,晴 10℃-27℃,0,0,0,5,5,5";
                    /*"txt6=820,85,2,2424,1,123a91,0,晴转多云10-27℃,200,24,0\r\n" +
                    "txtparam6=2,0";*/
		int ret = novaTraffic.sendPlayList(1, content);
		System.out.println(ret);
	}
}
